﻿<splx:SplxUserControl x:Class="SuplexApp.LogicRuleCtrl" Name="logicRuleCtrl"
                   KeyDown="logicRuleCtrl_KeyDown"
                   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                   xmlns:local="clr-namespace:SuplexApp"
                   xmlns:cc="clr-namespace:SuplexApp.Controls"
                   xmlns:splx="clr-namespace:Suplex.Wpf;assembly=Suplex.Wpf">
    <UserControl.Resources>
        <local:FormattingConverter x:Key="formatter" />

        <Style x:Key="ExpanderTextBlock" TargetType="{x:Type TextBlock}">
            <Setter Property="Foreground" Value="DarkBlue"/>
        </Style>
        <Style x:Key="ExpanderStackPanel" TargetType="{x:Type StackPanel}">
            <Setter Property="Margin" Value="7,0,0,0"/>
        </Style>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot">
        <Grid.ColumnDefinitions>
            <ColumnDefinition MaxWidth="700" MinWidth="400"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid HorizontalAlignment="Stretch">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>

            <StackPanel Orientation="Horizontal">
                <TextBlock Margin="5,5,0,5" FontSize="14" FontWeight="Bold" VerticalAlignment="Center" Foreground="DarkBlue"
                           TextBlock.Text="Rule: "/>
                <TextBlock Margin="0,5,0,5" FontSize="14" FontWeight="Bold" VerticalAlignment="Center"
                           TextBlock.Text="{Binding Path=Name}"/>
                <TextBlock Margin="0,5,0,5" FontSize="18" FontWeight="Bold" VerticalAlignment="Top" Foreground="Red"
                           TextBlock.Text="*"
                           Visibility="{local:FormattedBinding Path=IsDirty, ValueIfTrue=Visible, ValueIfFalse=Collapsed}"/>
            </StackPanel>
            <StackPanel HorizontalAlignment="Right" Orientation="Horizontal" Grid.Column="1">
                <Button Name="cmdOk" Content="Save"
                        VerticalAlignment="Center" MinHeight="20" Padding="5,0,5,0"
                        IsEnabled="{local:FormattedBinding Path=IsDirty}"
                        Click="cmdOk_Click"/>
                <Button Name="cmdCancel" Content="Discard"
                        VerticalAlignment="Center" MinHeight="20" Padding="5,0,5,0" Margin="5,0,0,0"
                        Click="cmdCancel_Click"/>
                <ToggleButton Name="cmdPanelToggler" Width="75" MinHeight="20" Margin="5,0,5,0" VerticalAlignment="Center"
                              Content="{local:FormattedBinding RelativeSource={RelativeSource Self}, Path=IsChecked, ValueIfTrue=Expand All, ValueIfFalse=Collapse All}"/>
            </StackPanel>
        </Grid>
        <ScrollViewer VerticalScrollBarVisibility="Auto" Grid.Row="1">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                <Expander Grid.Row="0" Margin="4"
                          IsExpanded="{local:FormattedBinding ElementName=cmdPanelToggler, Path=IsChecked, ValueIfTrue=False, ValueIfFalse=True, UpdateSourceTrigger=Explicit}">
                    <Expander.Header>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="Properties" Style="{DynamicResource ExpanderTextBlock}"/>
                            <StackPanel Orientation="Horizontal" Style="{DynamicResource ExpanderStackPanel}"
                                        Visibility="{local:FormattedBinding Path=IsExpanded, RelativeSource={RelativeSource AncestorType={x:Type Expander}}, ValueIfTrue=Collapsed, ValueIfFalse=Visible}">
                                <!--<TextBlock Text="{local:FormattedBinding Path=Name, FormatString='Name: \{0\}'}"/>-->
                                <TextBlock Text="{local:FormattedBinding Path=EventBinding, FormatString='[Event Binding: \{0\}]'}"/>
                            </StackPanel>
                        </StackPanel>
                    </Expander.Header>
                    <StackPanel Margin="5">
                        <StackPanel>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="105"/>
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <Label x:Name="lblName" Content="Name:" Style="{DynamicResource DialogLabel}"/>
                                <splx:SplxTextBox Name="txtName" Grid.Column="2" Style="{DynamicResource DialogTextBox}"
                                               Text="{Binding Path=Name, UpdateSourceTrigger=PropertyChanged}" TextChanged="Something_Changed"/>
                            </Grid>
                        </StackPanel>
                        <StackPanel>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="105"/>
                                    <ColumnDefinition MaxWidth="300" MinWidth="200"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>

                                <Label x:Name="lblEventBinding" Content="Event Binding:" Style="{DynamicResource DialogLabel}"/>
                                <splx:SplxComboBox Grid.Column="1" Name="cmbEventBinding"
                                                   Style="{DynamicResource DialogControl}"
                                                   IsEditable="False" IsReadOnly="False"
                                                   SelectionChanged="Something_SelectionChanged"
                                                   SelectedItem="{Binding Path=EventBinding}"/>

                                <Label x:Name="lblSortOrder" Grid.Column="3" Content="Sort Order:" Style="{DynamicResource DialogLabel}"/>
                                <splx:SplxTextBox Grid.Column="4" Width="40" Name="txtSortOrder"
                                               Style="{DynamicResource DialogTextBox}"
                                               Text="{Binding Path=SortOrder, UpdateSourceTrigger=PropertyChanged}" TextChanged="Something_Changed"/>
                            </Grid>
                        </StackPanel>
                    </StackPanel>
                </Expander>
                <Expander Grid.Row="1" Margin="4"
                          IsExpanded="{local:FormattedBinding ElementName=cmdPanelToggler, Path=IsChecked, ValueIfTrue=False, ValueIfFalse=True, UpdateSourceTrigger=Explicit}">
                    <Expander.Header>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="Clause" Style="{DynamicResource ExpanderTextBlock}"/>
                            <StackPanel Orientation="Horizontal" Style="{DynamicResource ExpanderStackPanel}"
                                                Visibility="{local:FormattedBinding Path=IsExpanded, RelativeSource={RelativeSource AncestorType={x:Type Expander}}, ValueIfTrue=Collapsed, ValueIfFalse=Visible}">
                                <TextBlock Text="{local:FormattedBinding Path=ValueType1, FormatString='[Value Type1: \{0\}'}"/>
                                <TextBlock Text="{local:FormattedBinding Path=CompareDataType, FormatString=', CompareAs: \{0\}'}"/>
                                <TextBlock Text="{local:FormattedBinding Path=ValueType2, FormatString=', Value Type2: \{0\}]'}"/>
                            </StackPanel>
                        </StackPanel>
                    </Expander.Header>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>

                        <Expander Grid.Row="0" Margin="4" Style="{DynamicResource GroupBoxStyle}"
                                  IsExpanded="{local:FormattedBinding ElementName=cmdPanelToggler, Path=IsChecked, ValueIfTrue=False, ValueIfFalse=True, UpdateSourceTrigger=Explicit}">
                            <Expander.Header>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="Left Operand" Style="{DynamicResource ExpanderTextBlock}"/>
                                    <StackPanel Orientation="Horizontal" Style="{DynamicResource ExpanderStackPanel}"
                                                Visibility="{local:FormattedBinding Path=IsExpanded, RelativeSource={RelativeSource AncestorType={x:Type Expander}}, ValueIfTrue=Collapsed, ValueIfFalse=Visible}">
                                        <TextBlock Text="{local:FormattedBinding Path=ValueType1, FormatString='[Value Type: \{0\}'}"/>
                                        <TextBlock Text="{local:FormattedBinding Path=ExpressionType1, FormatString=', Expression Type: \{0\}]'}"/>
                                    </StackPanel>
                                </StackPanel>
                            </Expander.Header>
                            <Grid Margin="5">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="105"/>
                                    <ColumnDefinition/>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>

                                <Label Content="Compare Value:" VerticalAlignment="Top" Style="{DynamicResource DialogLabel}" />
                                <splx:SplxTextBox Grid.ColumnSpan="3" Grid.Column="1" MinLines="4"
                                               Style="{DynamicResource DialogTextBox}"
                                               Name="txtCompareValue1" AcceptsReturn="True" VerticalScrollBarVisibility="Auto"
                                               TextChanged="Something_Changed"
                                               Text="{Binding Path=CompareValue1, UpdateSourceTrigger=PropertyChanged}"/>

                                <Label Content="Value Type:" Grid.Row="1" Style="{DynamicResource DialogLabel}"/>
                                <splx:SplxComboBox Grid.Row="1" Grid.Column="1"
                                                Style="{DynamicResource DialogControl}"
                                                Name="cmbValueType1"
                                                SelectionChanged="Something_SelectionChanged"
                                                SelectedItem="{Binding Path=ValueType1}"/>

                                <Label Content="Expression Type:" Grid.Row="1" Grid.Column="2" Style="{DynamicResource DialogLabel}"/>
                                <splx:SplxComboBox Grid.Row="1" Grid.Column="3"
                                                Style="{DynamicResource DialogControl}"
                                                Name="cmbExpressionType1"
                                                SelectionChanged="Something_SelectionChanged"
                                                SelectedItem="{Binding Path=ExpressionType1}"/>
                            </Grid>
                        </Expander>
                        <Expander Grid.Row="1" Margin="4" Style="{DynamicResource GroupBoxStyle}"
                                  IsExpanded="{local:FormattedBinding ElementName=cmdPanelToggler, Path=IsChecked, ValueIfTrue=False, ValueIfFalse=True, UpdateSourceTrigger=Explicit}">
                            <Expander.Header>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="Comparison" Style="{DynamicResource ExpanderTextBlock}"/>
                                    <StackPanel Orientation="Horizontal" Style="{DynamicResource ExpanderStackPanel}"
                                                Visibility="{local:FormattedBinding Path=IsExpanded, RelativeSource={RelativeSource AncestorType={x:Type Expander}}, ValueIfTrue=Collapsed, ValueIfFalse=Visible}">
                                        <TextBlock Text="{local:FormattedBinding Path=CompareDataType, FormatString='[Type: \{0\}'}"/>
                                        <TextBlock Text="{local:FormattedBinding Path=Operator, FormatString=', Operator: \{0\}]'}"/>
                                    </StackPanel>
                                </StackPanel>
                            </Expander.Header>
                            <StackPanel Margin="5">
                                <StackPanel>
                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="105"/>
                                            <ColumnDefinition Width="*" MaxWidth="250" MinWidth="100"/>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="*" MaxWidth="250" MinWidth="100"/>
                                        </Grid.ColumnDefinitions>
                                        <Grid.RowDefinitions>
                                            <RowDefinition />
                                        </Grid.RowDefinitions>

                                        <Label x:Name="lblDataType" Content="Data Type:" Style="{DynamicResource DialogLabel}"/>
                                        <splx:SplxComboBox Grid.Column="1" Name="cmbCompareDataType"
                                                        Style="{DynamicResource DialogControl}"
                                                        IsEditable="False" IsReadOnly="False"
                                                        SelectionChanged="Something_SelectionChanged"
                                                        SelectedItem="{Binding Path=CompareDataType}"/>

                                        <Label Grid.Column="2" x:Name="lblOperator" Content="Operator:" Style="{DynamicResource DialogLabel}"/>
                                        <splx:SplxComboBox Grid.Column="3" Name="cmbOperator"
                                                        Style="{DynamicResource DialogControl}"
                                                        IsEditable="False" IsReadOnly="False"
                                                        SelectionChanged="Something_SelectionChanged"
                                                        SelectedItem="{Binding Path=Operator}"/>
                                    </Grid>
                                </StackPanel>
                            </StackPanel>
                        </Expander>
                        <Expander Grid.Row="2" Margin="4" Style="{DynamicResource GroupBoxStyle}"
                                  IsExpanded="{local:FormattedBinding ElementName=cmdPanelToggler, Path=IsChecked, ValueIfTrue=False, ValueIfFalse=True, UpdateSourceTrigger=Explicit}">
                            <Expander.Header>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="Right Operand" Style="{DynamicResource ExpanderTextBlock}"/>
                                    <StackPanel Orientation="Horizontal" Style="{DynamicResource ExpanderStackPanel}"
                                                Visibility="{local:FormattedBinding Path=IsExpanded, RelativeSource={RelativeSource AncestorType={x:Type Expander}}, ValueIfTrue=Collapsed, ValueIfFalse=Visible}">
                                        <TextBlock Text="{local:FormattedBinding Path=ValueType2, FormatString='[Value Type: \{0\}'}"/>
                                        <TextBlock Text="{local:FormattedBinding Path=ExpressionType2, FormatString=', Expression Type: \{0\}]'}"/>
                                    </StackPanel>
                                </StackPanel>
                            </Expander.Header>
                            <Grid Margin="5">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="105"/>
                                    <ColumnDefinition/>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="Auto"/>
                                </Grid.RowDefinitions>

                                <Label Content="Compare Value:" VerticalAlignment="Top" Style="{DynamicResource DialogLabel}"/>
                                <splx:SplxTextBox Grid.ColumnSpan="3" Grid.Column="1" MinLines="4" Style="{DynamicResource DialogTextBox}"
                                               Name="txtCompareValue2"
                                               AcceptsReturn="True" VerticalScrollBarVisibility="Auto"
                                               TextChanged="Something_Changed"
                                               Text="{Binding Path=CompareValue2, UpdateSourceTrigger=PropertyChanged}"/>

                                <Label Content="Value Type:" Grid.Row="1" Style="{DynamicResource DialogLabel}"/>
                                <splx:SplxComboBox Grid.Row="1" Grid.Column="1"
                                                Style="{DynamicResource DialogControl}"
                                                Name="cmbValueType2"
                                                SelectionChanged="Something_SelectionChanged"
                                                SelectedItem="{Binding Path=ValueType2}"/>

                                <Label Content="Expression Type:" Grid.Row="1" Grid.Column="2" Style="{DynamicResource DialogLabel}"/>
                                <splx:SplxComboBox Grid.Row="1" Grid.Column="3"
                                                Style="{DynamicResource DialogControl}"
                                                Name="cmbExpressionType2"
                                                SelectionChanged="Something_SelectionChanged"
                                                SelectedItem="{Binding Path=ExpressionType2}"/>
                            </Grid>
                        </Expander>
                    </Grid>
                </Expander>
                <Expander Grid.Row="2" Margin="4"
                          IsExpanded="{local:FormattedBinding ElementName=cmdPanelToggler, Path=IsChecked, ValueIfTrue=False, ValueIfFalse=True, UpdateSourceTrigger=Explicit}">
                    <Expander.Header>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="Result" Style="{DynamicResource ExpanderTextBlock}"/>
                            <StackPanel Orientation="Horizontal" Style="{DynamicResource ExpanderStackPanel}"
                                        Visibility="{local:FormattedBinding Path=IsExpanded, RelativeSource={RelativeSource AncestorType={x:Type Expander}}, ValueIfTrue=Collapsed, ValueIfFalse=Visible}">
                                <TextBlock Text="{local:FormattedBinding Path=FailParent, ValueIfTrue='Stop: Fail the logic branch', ValueIfFalse='Continue: Process child logic', FormatString='[On Failure: \{0\}]'}"/>
                            </StackPanel>
                        </StackPanel>
                    </Expander.Header>
                    <Grid Margin="5">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto" Name="ResultRow1"/>
                            <RowDefinition Height="Auto" Name="ResultRow2"/>
                            <RowDefinition Height="Auto" Name="ResultRow3"/>
                        </Grid.RowDefinitions>

                        <Label Content="On Failure:" Style="{DynamicResource DialogLabel}"/>
                        <StackPanel Grid.Column="1" Orientation="Horizontal" Style="{DynamicResource DialogStackPanel}" VerticalAlignment="Center">
                            <splx:SplxRadioButton Name="chkFailParent" Content="Stop: Fail the logic branch"
                                               Margin="0,0,10,0" IsCheckedFixed="{Binding Path=FailParent}"
                                               Checked="Something_CheckChanged" Unchecked="Something_CheckChanged"/>
								
                            <splx:SplxRadioButton Content="Continue: Process child logic"
                                               Checked="Something_CheckChanged" Unchecked="Something_CheckChanged"
                                               IsCheckedFixed="{local:FormattedBinding Path=FailParent, ValueIfTrue=False, ValueIfFalse=True, UpdateSourceTrigger=PropertyChanged}"/>
                        </StackPanel>

                        <Label Content="Error Message:" Grid.Row="1" VerticalAlignment="Top" Style="{DynamicResource DialogLabel}"/>
                        <splx:SplxTextBox Grid.Row="1" Grid.Column="1" MinLines="4" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto"
                                       Style="{DynamicResource DialogTextBox}"
                                       Name="txtErrorMsg" VerticalAlignment="Top" AcceptsReturn="True"
                                       TextChanged="Something_Changed" Text="{Binding Path=ErrorMessage, UpdateSourceTrigger=PropertyChanged}"/>

                        <Label Content="Alt Error Element:" Grid.Row="2" Grid.Column="0" Style="{DynamicResource DialogLabel}"/>
                        <splx:SplxTextBox Grid.Row="2" Grid.Column="1" Name="txtAltErrorElement"
                                       Style="{DynamicResource DialogTextBox}"
                                       TextChanged="Something_Changed" Text="{Binding Path=ErrorControl, UpdateSourceTrigger=PropertyChanged}" />

                        <Label Content="Right Roles:" Grid.Row="3" Grid.Column="0"
                               VerticalAlignment="Top" Style="{DynamicResource DialogLabel}" Margin="0,5,5,0"/>
                        <StackPanel Grid.Row="3" Grid.Column="1" Style="{DynamicResource DialogStackPanel}">
                            <ToolBar>
                                <Button Name="cmdRightRoleAddSuccess" Content="Add Success Role" Click="cmdRightRoleAdd_Click" />
                                <Button Name="cmdRightRoleAddFailure" Content="Add Failure Role" Click="cmdRightRoleAdd_Click" />
                                <Button Name="cmdRightRoleEdit" Content="Edit Selected" />
                                <Button Name="cmdRightRoleDelete" Content="Delete Selected" />
                            </ToolBar>
                            <ListView Name="lvRightRoles" MinHeight="100" MaxHeight="300" MouseDoubleClick="lvRightRoles_MouseDoubleClick">
                                <ListView.View>
                                    <GridView>
                                        <GridViewColumn DisplayMemberBinding="{Binding Path=RightRoleType}" Header="Type" Width="75"/>
                                        <GridViewColumn DisplayMemberBinding="{Binding Path=ControlUniqueName}" Header="UniqueName" Width="100"/>
                                        <GridViewColumn DisplayMemberBinding="{Binding Path=AceType}" Header="Ace Type" Width="100"/>
                                        <GridViewColumn DisplayMemberBinding="{Binding Path=RightName}" Header="Right" Width="100"/>
                                        <GridViewColumn DisplayMemberBinding="{Binding Path=UIRight}" Header="UI Right" Width="100"/>
                                    </GridView>
                                </ListView.View>
                            </ListView>
                        </StackPanel>
                    </Grid>
                </Expander>
                <splx:ValidationSummary Grid.Row="3" Name="vs" Margin="4" />
            </Grid>
        </ScrollViewer>
    </Grid>
</splx:SplxUserControl>